package com.qf.feign;

import com.qf.pojo.Customer;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

/**
 *
 * 远程调用搜索微服务  Feign    @FeignClient(value = "QF-SEARCH")//1: 微服务名称:
 * @author lixu
 *
 * fallback :  回调    SearchFeignImpl.class:降级处理的实现类
 *
 * rollback
 *
 * SearchFeign: 真正的实现类是反射出来了  SearchFeign /search/find
 *
 * @Component
 * SearchFeignImpl：/feign/search/find"
 */
@FeignClient(value = "QF-SEARCH",fallback = SearchFeignImpl.class)//1: 微服务名称
//@RequestMapping(value = "/search")
public interface SearchFeign {


    /**
     * 发出请求
     */
    //@GetMapping("/search/find") //2:路径
    //4: 返回值类型 String
    //String find(String name,Integer age);//3：入参
    /**
     * 测试
     */
    @GetMapping("/search/find") // 默认POST请求
    //public String find(String name,Integer age);
    String find();

    /**
     * 远程 调用 Feign
     * @param name
     * @param age
     * @param flag
     * @return
     */
    @GetMapping("/search/findByName")
    String findByName(@RequestParam(value = "name") String name,
                             @RequestParam(value = "age") Integer age,
                             @RequestParam(value = "flag") Boolean flag);

    /**
     * 测试
     *  rest风格  restFul风格
     * http://localhost:9001/search/findByName/name/age/flag
     */
    @GetMapping("/search/findByPath/{name}/{age}/{flag}")
    String findByPath(
            @PathVariable(value = "name") String name,
            @PathVariable(value = "age") Integer age,
            @PathVariable(value = "flag") Boolean flag
    );
    /**
     *  接收JSON串
     *  @RequestBody:
     */
    @PostMapping("/search/findRequestBody")
    Customer findRequestBody(@RequestBody Customer customer);




    /**
     * 根据ID查询一个对象
     */
    @GetMapping("/hystrix/findById")
    public Customer findById1(@RequestParam(value = "id") Integer id);

    /**
     * 模拟根据id查询
     * @param id
     */
    @GetMapping("/search/{id}")
    Customer findById(@PathVariable(value = "id") Integer id);

}
